<template>
  <div class="audit-box">
    <el-alert title="审核"
              class="alert-box"
              type="success"
              center
              show-icon
              :closable="false">
    </el-alert>
    <el-form ref="auditForm"
             :model="auditForm"
             :label-width="labelWidth"
             :disabled="opType!=='audit'">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="examinePeople"
                        label="审核人员"
                        :rules="[required]">
            <el-input v-model.trim="auditForm.examinePeople"
                      :maxlength="20"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="status"
                        label="审核状态"
                        :rules="[required]">
            <el-radio-group v-model="auditForm.status">
              <el-radio label="2">通过</el-radio>
              <el-radio label="3">未通过</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item prop="examineDes"
                        label="审核说明">
            <el-input placeholder=""
                      type="textarea"
                      :rows="3"
                      resize="none"
                      :maxlength="500"
                      v-model.trim="auditForm.examineDes"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'WaterSaveSingleAudit',
  props: {
    opType: {
      type: String,
      default: 'audit'
    },
    labelWidth: {
      type: String,
      default: '130px'
    },
  },
  data() {
    return {
      auditForm: {
        examinePeople: '',
        status: '2',
        examineDes: ''
      },
      required: {
        required: true,
        message: '必填，不能为空',
        trigger: ['blur', 'change']
      }
    }
  },
  computed: {
    ...mapGetters(['name'])
  },
  methods: {
    resetForm(auditData, flag = '') {
      this.$nextTick(() => {
        let name = this.name;
        this.$refs.auditForm.resetFields();
        this.auditForm.examinePeople = name;
        // 如果是查看，赋值审核信息
        if (this.opType !== 'audit' && this.opType !== 'add') {
          this.assignmentAuditForm(auditData, flag);
        }
      })
    },
    // 赋值表单 flag 有值是审核数据和之前审核数据不一样的页面
    assignmentAuditForm(auditData, flag) {
      if (!flag) {
        this.auditForm.status = auditData.status
        this.auditForm.examinePeople = auditData.examinePeople
        this.auditForm.examineDes = auditData.examineDes
      } else {
        this.auditForm.status = auditData.shjg
        this.auditForm.examinePeople = auditData.shry
        this.auditForm.examineDes = auditData.shyj
      }
    },
    handleAudit() {
      this.$refs.auditForm.validate(async (valid) => {
        if (valid) {
          this.$emit('singleAuditSubmit', this.auditForm);
        } else {
          this.msgWarning('请正确填写审核表单内容')
        }
      });
    }
  },
}
</script>

<style lang="scss" scoped>
.alert-box {
  margin-bottom: 6px;
}
</style>